//
//  PersonalHeadView.m
//  ChatForHot
//
//  Created by wr on 2018/10/9.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "PersonalHeadView.h"
#import "APPINFO.h"

@interface PersonalHeadView ()

@property (nonatomic, strong) UIImageView *HOTCHATpickAvatarImage;
@property (nonatomic, strong) UILabel *HOTCHATuserNameLabel;
@property (nonatomic, strong) UILabel *HOTCHATuserIdLabel;
@property (nonatomic, strong) UIImageView *HOTCHATvipBackImageView;
@property (nonatomic, strong) UIImageView *HOTCHATvipIcon;
@property (nonatomic, strong) UILabel *HOTCHATvipLabel;
@property (nonatomic ,strong) UIImageView *HOTCHATarrowMark;
@property (nonatomic ,strong, readwrite) RACSubject *avatarDidSelected;
@property (nonatomic ,strong, readwrite) RACSubject *vipDidSelected;

@end

@implementation PersonalHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.userInteractionEnabled = YES;
        [self HOTCHATdidInitialized];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self HOTCHATdidInitialized];
    }
    return self;
}

- (void)HOTCHATdidInitialized {
    self.backgroundColor = [UIColor whiteColor];
    
    self.avatarDidSelected = [[RACSubject alloc] init];
    self.vipDidSelected = [[RACSubject alloc] init];

    
    self.HOTCHATpickAvatarImage = [[UIImageView alloc] init];
    self.HOTCHATpickAvatarImage.clipsToBounds = YES;
    self.HOTCHATpickAvatarImage.contentMode = UIViewContentModeScaleAspectFill;
    self.HOTCHATpickAvatarImage.layer.masksToBounds = YES;
    self.HOTCHATpickAvatarImage.layer.cornerRadius = 170 / 2;
    [self addSubview:self.HOTCHATpickAvatarImage];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(HOTCHATAvatarClick)];
    [self.HOTCHATpickAvatarImage addGestureRecognizer:tap];
    self.HOTCHATpickAvatarImage.userInteractionEnabled = YES;
    
    self.HOTCHATuserNameLabel = [[UILabel alloc] init];
    self.HOTCHATuserNameLabel.font = [UIFont systemFontOfSize:21];
    self.HOTCHATuserNameLabel.textAlignment = NSTextAlignmentCenter;
    self.HOTCHATuserNameLabel.textColor = [UIColor colorFromHexString:@"111111"];
    [self addSubview:self.HOTCHATuserNameLabel];
    
    self.HOTCHATuserIdLabel = [[UILabel alloc] init];
    self.HOTCHATuserIdLabel.font = [UIFont systemFontOfSize:16];
    self.HOTCHATuserIdLabel.textAlignment = NSTextAlignmentCenter;
    self.HOTCHATuserIdLabel.textColor = [UIColor colorFromHexString:@"333333"];
    [self addSubview:self.HOTCHATuserIdLabel];
    
    self.HOTCHATvipBackImageView = [[UIImageView alloc] init];
    [self.HOTCHATvipBackImageView setImage:[[UIImage imageNamed:@"vip_bk_image"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10) resizingMode:(UIImageResizingModeStretch)]];
    [self addSubview:self.HOTCHATvipBackImageView];
    UITapGestureRecognizer *vipTap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [self.vipDidSelected sendNext:nil];
    }];
    self.HOTCHATvipBackImageView.userInteractionEnabled = YES;
    [self.HOTCHATvipBackImageView addGestureRecognizer:vipTap];
    
    self.HOTCHATvipIcon = [[UIImageView alloc] init];
    [self.HOTCHATvipIcon setImage:[UIImage imageNamed:@"personal_vip"]];
    self.HOTCHATvipIcon.clipsToBounds = YES;
    self.HOTCHATvipIcon.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.HOTCHATvipIcon];
    
    self.HOTCHATvipLabel = [[UILabel alloc] init];
    self.HOTCHATvipLabel.font = [UIFont systemFontOfSize:18];
    self.HOTCHATvipLabel.text = NSLocalizedString(@"person2_1", nil);
    self.HOTCHATvipLabel.textColor = [UIColor colorFromHexString:@"111111"];
    [self addSubview:self.HOTCHATvipLabel];
    
    self.HOTCHATarrowMark = [[UIImageView alloc] init];
    [self.HOTCHATarrowMark setImage:[UIImage imageNamed:@"personal_arrow"]];
    self.HOTCHATarrowMark.clipsToBounds = YES;
    self.HOTCHATarrowMark.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.HOTCHATarrowMark];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.HOTCHATpickAvatarImage.size = CGSizeMake(170, 170);
    self.HOTCHATpickAvatarImage.top = 26;
    self.HOTCHATpickAvatarImage.backgroundColor = [UIColor redColor];
    self.HOTCHATpickAvatarImage.centerX = self.centerX;
    
    self.HOTCHATuserNameLabel.size = CGSizeMake(kScreenWidth - 30, 30);
    self.HOTCHATuserNameLabel.centerX = self.centerX;
    self.HOTCHATuserNameLabel.top = self.HOTCHATpickAvatarImage.bottom + 10;
    
    self.HOTCHATuserIdLabel.size = CGSizeMake(kScreenWidth - 30, 22);
    self.HOTCHATuserIdLabel.top = self.HOTCHATuserNameLabel.bottom + 4;
    self.HOTCHATuserIdLabel.centerX = self.centerX;
    
    self.HOTCHATvipBackImageView.size = CGSizeMake(kScreenWidth - 30, 75);
    self.HOTCHATvipBackImageView.top = self.HOTCHATuserIdLabel.bottom + 28;
    self.HOTCHATvipBackImageView.left = 15;
    
    self.HOTCHATvipIcon.size = CGSizeMake(35, 35);
    self.HOTCHATvipIcon.left = 36;
    self.HOTCHATvipIcon.centerY = self.HOTCHATvipBackImageView.centerY;
    
    self.HOTCHATvipLabel.size = CGSizeMake(kScreenWidth - 89 - 40, 20);
    self.HOTCHATvipLabel.left = self.HOTCHATvipIcon.right + 17;
    self.HOTCHATvipLabel.centerY = self.HOTCHATvipIcon.centerY;
    
    self.HOTCHATarrowMark.size = CGSizeMake(7, 11);
    self.HOTCHATarrowMark.left = kScreenWidth - 25 - 15;
    self.HOTCHATarrowMark.centerY = self.HOTCHATvipBackImageView.centerY;
}

- (void)HOTCHATbind {
    self.HOTCHATuserNameLabel.text = [APPINFO defaultManager].nickName;
    self.HOTCHATuserIdLabel.text = [NSString stringWithFormat:@"ID:%@",[APPINFO defaultManager].accountNumber];
    [self.HOTCHATpickAvatarImage simple_setImageWithURL:[NSString stringWithFormat:@"%@%@",APIHEADER,[APPINFO defaultManager].headPic] placeholderImage:[UIImage imageNamed:@"personal_atatar_but_n"]];
}

- (void)HOTCHATAvatarClick {
    [self.avatarDidSelected sendNext:nil];
}
@end
